#!/usr/bin/perl
require Algorithm::Diff;
####################################################
#Main Route Entry Point
####################################################
if(@ARGV < 2){
	die "Not enough arguments, please input two strings.\n";
}
$fileA=$ARGV[0] || "-";
$fileB=$ARGV[1] || "-";
open FA, $fileA;
open FB, $fileB;
#open FA_OT, ">$fileA.ot";
#open FB_OT, ">$fileB.ot";
while(<FA>){
	s/\r\n/\n/g;
	s/\r/\n/g;
	$strA .= $_;
}
while(<FB>){
	s/\r\n/\n/g;
	s/\r/\n/g;
	$strB .= $_;
}
#chomp($strA);
#chomp($strB);
#print FA_OT $strA."\n";
#print FB_OT $strB."\n";
@seq1=split(//,$strA);
@seq2=split(//,$strB);
#print "FileA:\n",@seq1,"EOF\n";
#print "FileB:\n",@seq2,"EOF\n";
#print "LengthA:",scalar @seq1,"\n";
#print "LengthB:",scalar @seq2,"\n";
#######################
#Test Case 1
#@seq1 = qw(a b c e h j l m n p);
#@seq2 = qw(b c d e f j k l m r s t);
#######################
#Test Case 2
#@seq1 = qw(A B C A B B A);
#@seq2 = qw(C B A B A C);
#######################
@diffs = Algorithm::Diff::sdiff(\@seq1,\@seq2);# Ref::http://kobesearch.cpan.org/htdocs/Algorithm-Diff/Algorithm/Diff.html
$p = 0; #The lenght of the target string
foreach $arr (@diffs){
	#print @$arr[0],"\t",@$arr[1],"\t",@$arr[2],"\n";
	if(@$arr[0] eq '-')
	{
		$char = unpack("c",@$arr[1]);
		#if($char eq "\n"){
		#	$char = '\n';
		#}
		print "del,".$p.",".$char.":";
	}
	if(@$arr[0] eq 'u')
	{
		$p += 1;
	}
	if(@$arr[0] eq '+')
	{
		$char = unpack("c",@$arr[2]);
		#if($char eq "\n"){
		#	$char = '\n';
		#}
		print "ins,".$p,",".$char.":";
		$p += 1;
	}
	if(@$arr[0] eq 'c')
	{
		$char1 = unpack("c",@$arr[1]);
		#if($char1 eq "\n"){
		#	$char1 = '\n';
		#}
		$char2 = unpack("c",@$arr[2]);
		#if($char2 eq "\n"){
		#	$char2 = '\n';
		#}
		print "del,".$p.",".$char1.":";
		print "ins,".$p.",".$char2.":";
		$p += 1;
	}
}
#print "\n";
